package com.springcloud.system.user.handler;

import com.springcloud.common.entity.SystemUser;
import com.springcloud.common.web.handler.DefaultMetaObjectHandler;
import com.springcloud.system.user.util.SystemUserContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Objects;
import java.util.Optional;

/**
 * <p>  </p>
 *
 * @author mori
 * @since 10/29/2019 11:16 AM
 */
@Component
@Slf4j
public class PoMetaObjectHandler extends DefaultMetaObjectHandler {

    private SystemUserContextHolder systemUserContextHolder;

    public PoMetaObjectHandler(SystemUserContextHolder systemUserContextHolder) {
        this.systemUserContextHolder = systemUserContextHolder;
    }

    @Override
    public String getCreatedBy() {
        return Optional.ofNullable(systemUserContextHolder.getContext())
                .map(SystemUser::getSystemUserId)
                .map(Objects::toString)
                .orElse(null);
    }
}
